<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of masterbiaya
 *
 * @author miyzan
 */
class masterbiaya extends MY_Controller{
    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->model("masterbiaya_model","mbiy");
        $this->load->library('../controllers/global_reference');
    }
    public function get_rows() {

        $page   =   ($this->input->post('page', TRUE) ? $this->input->post('page', TRUE) : 1);
        $start = isset($_POST['start']) ? $this->db->escape_str($this->input->post('start', TRUE)) : 0;
        $limit = isset($_POST['limit']) ? $this->db->escape_str($this->input->post('limit', TRUE)) : $this->config->item("length_records");
        $search = isset($_POST['query']) ? $this->db->escape_str($this->input->post('query', TRUE)) : '';

        $result = $this->mbiy->get_rows($search, $start, $limit);
        echo $result;
    }
    public function get_rows_combo() {

        $result = $this->mbiy->get_rows_combo();
        echo $result;
    }
    
    public function update_rows()
    {
        $opt = isset($_POST['cmd']) ? $this->db->escape_str($this->input->post('cmd', TRUE)) : '';
        $kd = isset($_POST['kd_biaya']) ? $this->db->escape_str($this->input->post('kd_biaya', TRUE)) : '';
        $idj = isset($_POST['id_jenis']) ? $this->db->escape_str($this->input->post('id_jenis', TRUE)) : '';
        $bid = isset($_POST['bi_dasar']) ? $this->db->escape_str($this->input->post('bi_dasar', TRUE)) : '';
        $ket = isset($_POST['keterangan']) ? $this->db->escape_str($this->input->post('keterangan', TRUE)) : '';
        if($opt=='insert'){
            
//            $gr=new global_reference();
            $kode='B';
            $rkode=  $this->global_reference->sequence($kode);
            $kd=$kode.'-'.$rkode[0]->retval;
        }
        $param=array($opt,$kd,$ket,$bid,$idj);
        $spname='sp_mst_biaya';
        $result = $this->mbiy->SP_execData($spname, $param, true);
        echo $result;        
    }
    
    public function delete_row()
    {
        $opt = isset($_POST['cmd']) ? $this->db->escape_str($this->input->post('cmd', TRUE)) : '';
        $data = isset($_POST['postdata']) ? json_decode($this->input->post('postdata', TRUE)): array(); 
        $kd = $data->kd_biaya;        
        $ket = $data->keterangan;        
        $bid = $data->biaya_dasar;        
        $idj = $data->id_jenis;        
        
        $param=array($opt,$kd,$ket,$bid,$idj);
        $spname='sp_mst_biaya';
        $result = $this->mbiy->SP_execData($spname, $param, true);
        echo $result;
        
    }
}

?>
